//
//  ThirdlubViewController.m
//  Project_B
//
//  Created by dllo on 15/11/24.
//  Copyright © 2015年 张闯. All rights reserved.
//

#import "ThirdlubViewController.h"
#import "MBProgressHUD.h"
#import "AFNetworkHandler.h"
#import "ThirdlubTableViewCell.h"
#import "ThirdlubModel.h"
#import "ThirdlubJumpViewController.h"
#import "RESideMenu.h"
#import "UIImage+GIF.h"


@interface ThirdlubViewController () < UITableViewDataSource, UITableViewDelegate >

@property (nonatomic, retain) UITableView *table;
@property (nonatomic, retain) NSMutableArray *clubArr;
@property (nonatomic, retain) MBProgressHUD *hud;


@end

@implementation ThirdlubViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.clubArr = [NSMutableArray array];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    self.navigationItem.title = @"俱乐部";
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-category"] style:UIBarButtonItemStylePlain target:self action:@selector(presentLeftMenuViewController:)];
    [self.navigationItem.leftBarButtonItem setTintColor:[UIColor whiteColor]];
    
    [self date];
    [self tableview];
    self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:NO];
    self.hud.animationType = MBProgressHUDAnimationFade;
}

#pragma mark - tablview
- (void)tableview
{

    self.table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 375, 667 - 64 - 44) style:UITableViewStylePlain];
    self.table.delegate = self;
    self.table.dataSource = self;
<<<<<<< HEAD
=======


>>>>>>> a1c9e5d1f262dc248cd920fdd98c55df3f101174
}

#pragma mark - 准备数据
- (void)date
{
    NSString *str = @"http://api.lis99.com/v3/club/index/?user_id=(null)?";
    [AFNetworkHandler getUrl:str cookie:nil result:^(id result) {
        
        NSArray *arr = result[@"data"][@"clubtyperank"];
        self.clubArr = [ThirdlubModel transformWithArray:arr.firstObject[@"typeranks"]];
        //移除小菊花

<<<<<<< HEAD

        [self.hud removeFromSuperview];
        [self.view addSubview:self.table];



        [self.hud removeFromSuperview];
        [self.view addSubview:self.table];

        [self.hud removeFromSuperview];
        [self.view addSubview:self.table];
=======
        [self.hud removeFromSuperview];
        [self.view addSubview:self.table];

>>>>>>> a1c9e5d1f262dc248cd920fdd98c55df3f101174
        [self.table reloadData];
    }];
    
}

#pragma mark - 页面将要出现
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = NO;
}

#pragma mark - tableView协议方法
#pragma mark - 行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.clubArr.count;
}

#pragma mark - 行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

#pragma mark - 单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ThirdlubTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
    if (!cell) {
        cell = [[ThirdlubTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell1"];
    }
    ThirdlubModel * model = [self.clubArr objectAtIndex:indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;//无选中颜色
    cell.model = model;
    
    return cell;
}

#pragma mark - 点击
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    ThirdlubJumpViewController * jamphot = [[ThirdlubJumpViewController alloc] init];
    jamphot.idString = [self.clubArr[indexPath.row] idear];
    [self.navigationController pushViewController:jamphot animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
